package com.gky.gkytemplate.test;

import com.auth0.jwt.interfaces.Claim;
import com.gky.gkytemplate.common.properties.JwtProperties;
import com.gky.gkytemplate.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
public class testJWT {

    @Resource
    private JwtProperties jwtProperties;

    @Test
    public void testToken(){
        Map<String, Object> map = new HashMap();
        map.put("userId","1");
        String token = JwtUtils.createJWT(jwtProperties.getSecretKey(),jwtProperties.getTtl(),map);
        System.out.println(token);
    }
    @Test
    public void testToken1(){
        Claims claims = JwtUtils.parseJWT(jwtProperties.getSecretKey(), "eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3Mjk4NTQ1NzksInVzZXJJZCI6MX0.pQAq0O6w96OFf_O6ad8VMQAkNRgw6Lx1Roj2hp0bZQo");
        System.out.println(claims);
        Long userId = Long.valueOf(claims.get("userId").toString());
        System.out.println(userId);
    }
}
